import scrapy


class BqgSpider(scrapy.Spider):
    """多页爬取"""
    name = 'bqg'
    # allowed_domains = ['www.xxx.com']
    start_urls = ['http://www.xbiquge.la/1/1710/1298266.html']
    
    demo_url = 'http://www.xbiquge.la/1/1710/129{}.html' # 8266-9003
    page_num = 8267

    def parse(self, response):
        title = response.xpath('//div[@class="bookname"]//text()')[1].extract()
        content = response.xpath('string(//*[@id="content"])')[0].extract()
        print(title, '\n' ,content)
        
        # if self.page_num < 9003:
        if self.page_num < 8267+10:
            url = self.demo_url.format(self.page_num)
            self.page_num += 1
            yield scrapy.Request(url=url, callback=self.parse)
        
        
            
        
        
    